﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Components;

namespace UI.ShopManagement
{
    public partial class FrmBas1a20 : UI.ParentForm.BaseMain
    {
        FrmBas1a20Edit edit = null;
        private ToolStripButton btnSetting = null;

        public FrmBas1a20(string modulecode, string action)
            : base(modulecode, action)
        {
            InitializeComponent();

            PageInit();
        }

        void PageInit()
        {
            btnSetting = base.CreateToolBtn("M", "门店参数设置", OnPrintBtnClick);

            this.tspTop.Items.Add(btnSetting);
        }

        private void OnPrintBtnClick(object sender, EventArgs e)
        {
            DataGridViewRow row = this.GetSelectedRow();
            if (null == row) return;

            var frm = new FrmBas1a22Edit("M", btnSetting.Text, Validation.ToString(row.Cells["listid"].Value));
            frm.ShowDialog();
        }

        protected override void OnAddClick(ToolStripButton btn)
        {
            edit = new FrmBas1a20Edit("A", GetTitleStyle(this.Text, btn.Text), "");
            edit.ShowDialog();
            if (edit.IsReload) base.BindGrid();
        }

        protected override void OnEditClick(ToolStripButton btn, DataGridViewRow row)
        {
            OpenEdit("M", btn.Text, Components.Validation.ToString(row.Cells["listid"].Value));
        }

        protected override void OnViewClick(ToolStripButton btn, DataGridViewRow row)
        {
            OpenEdit("V", btn.Text, Components.Validation.ToString(row.Cells["listid"].Value));
        }

        private void OpenEdit(string action, string btnText, string code)
        {
            edit = new FrmBas1a20Edit(action, GetTitleStyle(this.Text, btnText), code);
            edit.ShowDialog();
            if (edit.IsReload) base.BindGrid();
        }

        protected override void UpdatePager(UI.Common.Pager pager)
        {
            pager.FilterAppName = "a.muser";
            pager.StrWhere = " a.statuscode <> '4' ";
        }
    }
}
